package com.itheima.io.objectoutputstream.demo01;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream ;

/**
 * 对象的反序列化(ObjectInputStream)
 */
public class ObjectInputStreamDemo01 {

    public static void main(String[] args) throws IOException, ClassNotFoundException {

        // 1. 创建流对象
        // public ObjectInputStream​(InputStream in)
        // 创建FileInputStream对象
        // FileInputStream fileInputStream = new FileInputStream("itheima-io-objectoutputstream\\obj.txt") ;

        // 创建ObjectInputStream​对象
        // ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream) ;

        ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("itheima-io-objectoutputstream\\obj.txt")) ;

        // 2. 读取数据
        // public final Object readObject​()
        Student student = (Student)objectInputStream.readObject() ;
        System.out.println(student.getName() + "----" + student.getAge());

        // student = (Student)objectInputStream.readObject() ;         // EOFException如果文件中没有数据了，那么我们再次进行读取的时候就会抛出EOFException
        // System.out.println(student.getName() + "----" + student.getAge());

        // 3. 释放资源
        objectInputStream.close();


    }
}
